<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let data = {
            name: '尚硅谷',
            address: '北京'
        }
        const obs = new Observer(data)
        let vm = {}
        vm._data = data = obs


        function Observer(obj) {
            const keys = Object.keys(obj)

            keys.forEach(key => {
                Object.defineProperty(this, key, {
                    get() {
                        return obj[key]
                    },
                    set(val) {
                        console.log(`${key}被改变！`);
                        obj[key] = val
                    }
                })
            })
        }
    </script>
</body>
</html>